package com.example.konwRice.index.Adapter;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.konwRice.index.Bean.RiceBean;
import com.example.konwRice.R;

import java.util.ArrayList;
public class riceAdapter extends BaseAdapter {
    public static ArrayList<RiceBean> list;
    private Context context;

    public riceAdapter(ArrayList<RiceBean> list, Context context) {
        this.context = context;
        this.list=list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder=null;
        if(convertView==null){
            viewHolder=new ViewHolder();
            convertView= LayoutInflater.from(context).inflate(R.layout.rice_type,null,false);
            viewHolder.imageView=(ImageView)convertView.findViewById(R.id.riceType_image);
            viewHolder.name=(TextView)convertView.findViewById(R.id.riceType_name);
            convertView.setTag(viewHolder);
        }
        viewHolder=(ViewHolder)convertView.getTag();
        Glide.with(context).load(list.get(position).getImageUrl()).into(viewHolder.imageView);
        viewHolder.name.setText(list.get(position).getName());
        return convertView;
    }
    class ViewHolder{
        private ImageView imageView;
        private TextView name;
    }
}
